package date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**本类用与测试SimpleDateFormat日期转换工具类*/
public class TestSDF {
    public static void main(String[] args) {
        Date d1 = new Date();
        Date d2 = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat();
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        String s1 = sdf.format(d1);
        String s2 = sdf2.format(d1);
        System.out.println(s1);
        System.out.println(s2);
    }
    /**
     * SimpleDateFormat
     * 日期转成自己想要的字符串格式
     */
    public  static void testStringToDate() {
        String s = "2017-05-25";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = format.parse(s);
        } catch (ParseException e) {
            System.out.println(e.getMessage());
        }
        System.out.println(date);
    }
}
